﻿@{
    Layout = "~/Views/Shared/_Layout_RTU_block.cshtml";
    ViewBag.Title = "Warn Setting";
}

<div class="xds-no-breadcrumb">

    <div class="full-height">
        <div class="full-height-scroll white-bg border-left">
            <div id="blocktable" style="text-align:center;">
            </div>
        </div>
    </div>
</div>

@section Styles {
    @Styles.Render("~/Content/plugins/iCheck/iCheckStyles")
    @Styles.Render("~/plugins/sweetAlertStyles")
    <style type="text/css">
        table tr td{
            padding:5px 0px 0px 10px;
        }
    </style>
}
@section Scripts {
    @Scripts.Render("~/plugins/iCheck")
    @*@Scripts.Render("~/plugins/videoResponsible")*@
    @Scripts.Render("~/plugins/sweetAlert")
    <script type="text/javascript">
        // Creat JSON url to controller
        var wellAllDataUrl = '@Url.Action("Block", "Map")';
        var wellOfBlockUrl = '@Url.Action("WellOfBlock", "WellList")';
        var div = $('#blocktable');
        $(document).ready(function () {
            // Ajax call for table data
            refresh();
        });
        function refresh() {
            if (sessionStorage.blockid == 0 || sessionStorage.blockid == null) {
                div.empty();
                $.ajax({
                    url: wellAllDataUrl,
                    method: 'GET',
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 7) {
                            swal({
                                title: "Welcome in Alerts!",
                                text: "Authority error."
                            });
                        }
                        else {
                            $.each(data.data, function (i, item) {
                                fillblocktable(item.ID, item.Name);
                            })
                        }
                    },
                    error: function () {
                        swal({
                            title: "Welcome in Alerts!",
                            text: "The connection between server and units is not very stable. For any technical assistant, please call 1-(517)-927-5910."
                        });

                    }
                });
            }
            else {
                div.empty();
                fillblocktable(sessionStorage.blockid, sessionStorage.blockname)
            }
        }
        function fillblocktable(blockid, blockname) {
            $.ajax({
                url: wellOfBlockUrl,
                method: 'GET',
                dataType: 'json',
                async: false,
                data: { blockid: blockid },
                success: function (data) {
                    if (data.status == 7) {
                        swal({
                            title: "Welcome in Alerts!",
                            text: "Authority error."
                        });
                    }
                    else {
                        //div.append('<div class="row"><div class="col-lg-12"><div class="ibox-title"><h5>' + blockname + '</h5></div><div class="ibox-content"><table class="table table-striped" id="ajaxTable' + blockid + '"><thead><tr><th style = "text-align:center;">油井编号</th><th style = "text-align:center;">油井名称</th><th style = "text-align:center;">油井状态</th><th style = "text-align:center;">警告关注</th></tr></thead><tbody></tbody></table></div></div></div>')
                        div.append('<div class="row"><div class="col-lg-12"><div class="ibox-title"><h5>' + blockname + '</h5></div><div class="ibox-content"><table class="table table-striped" id="ajaxTable' + blockid + '"><thead><tr><th style = "text-align:center;">Well No. </th><th style = "text-align:center;">API No. </th><th style = "text-align:center;">Status</th><th style = "text-align:center;">Alarm Settings</th></tr></thead><tbody></tbody></table></div></div></div>')
                        littlediv = $('#ajaxTable' + blockid);
                        $.each(data.data, function (i, item) {
                            //littlediv.append('<tr><td>' + item.Name1 + '</td><td>' + item.Name2 + '</td><td>' + item.Chinese + '</td><td><button type="button" onclick="gotosubscribe(' + item.ID + ')" class="btn btn-xs btn-primary">设置</button></td></tr>'
                            littlediv.append('<tr><td>' + item.Name1 + '</td><td>' + item.Name2 + '</td><td>' + item.Status + '</td><td><button type="button" onclick="gotosubscribe(' + item.ID + ')" class="btn btn-xs btn-primary">Configure</button></td></tr>'
                                );
                        })
                    }
                },
                error: function () {
                    swal({
                        title: "Welcome in Alerts!",
                        text: "The connection between server and units is not very stable. For any technical assistant, please call 1-(517)-927-5910."
                    });

                }
            });
        }
        function gotosubscribe(id) {
            sessionStorage.wellid = id;
            window.open("/Personal/WarnLogSubscribe", "_self")
        }
    </script>
}